function [tmat, stype, bsize] = analyzetype(anatype)
% analyzetype  - return properties of analyze image datatype
%
% FORMAT:       [anadata, anareadtype, anareadsize] = analyzetype(anatype)
%
% Input fields:
%
%       anatype     numeric datatype given in Analyze header
%
% Output fields:
%
%       anadata     1x1 data field with correct type and zero content
%       anareadtype type string for fread operations
%       anareadsize number of bytes per pixel/voxel

% Version:  v0.8a
% Build:    9102220
% Date:     Oct-22 2009, 8:36 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~isa(anatype, 'double') || ...
    numel(anatype) ~= 1 || ...
    isnan(anatype) || ...
    isinf(anatype) || ...
    anatype < 2
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid argument for call to %s.', ...
        mfilename ...
    );
end

% double check
while anatype > 256
    anatype = fix(anatype / 256);
end
switch anatype
    case {2},   bsize = 1; tmat = uint8(0);  stype = 'uint8=>uint8';
    case {4},   bsize = 2; tmat = int16(0);  stype = 'int16=>int16';
    case {8},   bsize = 4; tmat = int32(0);  stype = 'int32=>int32';
    case {16},  bsize = 4; tmat = single(0); stype = 'single=>single';
    case {64},  bsize = 8; tmat = 0;         stype = 'double=>double';
    case {130}, bsize = 1; tmat = int8(0);   stype = 'int8=>int8';
    case {132}, bsize = 2; tmat = uint16(0); stype = 'uint16=>uint16';
    case {136}, bsize = 4; tmat = uint32(0); stype = 'uint32=>uint32';
    otherwise
        error( ...
            'BVQXtools:BadArgument', ...
            'Invalid anatype value: %d.', ...
            anatype ...
        );
end
